<template>
    <div id="app" :class="`theme-${themeColor}`">
      <router-view></router-view> 
    </div>
</template>
<script>
import navbar from './components/navbar'
import Footerbar from './components/footer'
import UserService from 'services/userService'
import SystemService from 'services/systemService'
export default {
  name: 'app',
  components: {
    navbar,
    Footerbar
  },
  computed: {
    login: function() {
      return this.$store.state.login.is_login
    }
  },
  watch: {
    login: function() {
      if (!this.login) {
        this.$router.push("/login")
      } else {
        this.$router.push("/")
      }
    }
  },
  mounted() {
    SystemService.getLicense()
      .then((res) => {
        if (res.errcode === 0) {
          this.$store.state.cert = res.cert
        }
      })
    UserService.getLoginInfo()
     .then((res) => {
        if (res.errcode === 0) {
          // this.$store.state.access = true
          // store.state.web_ui = res.data.web_ui
          // store.state.time = res.data.web_ui
          this.$store.commit('EDIT_LOGIN', res)
          
          setInterval(()=>{
            if (res.is_login) {
                this.$store.state.web_ui -= 1
                if (this.$store.state.web_ui === 0) { 
                  userService.logout()
                  eventEmitter.emit('timeout_Event');
                }
            }
          },1000)
       }
    })
  }
}
</script>
